/**
 * 这里基于day.js 二次封装的一些功能
 * https://dayjs.fenxianglu.cn/
 */
(function (global, factory) {
    typeof exports === 'object' && typeof module !== 'undefined' ? (module.exports = factory()) : typeof define === 'function' && define.amd ? define(factory) : ((global = global || self), (global.dateUtils = factory()));
})(this, function () {
    /**
     * 获取两日期之间的日期遍历数组
     * @param startDate 开始时间
     * @param endDate   结束时间
     * @param offset    平移天数
     * @param format 输出格式
     * @returns {*[]}
     */
    function getDatesBetween(startDate, endDate, offset = 0, format = 'YYYY-MM-DD') {
        const start = dayjs(startDate);
        const end = dayjs(endDate);

        if (end.isBefore(start)) {
            throw new Error('End date should be greater than start date.');
        }

        const diffInDays = end.diff(start, 'day');
        return Array.from({length: diffInDays + 1}, (_, index) =>
            start.add(index + offset, 'day').format(format)
        );
    }

    return {
        getDatesBetween
    };
});
